from django import template
from string import capwords
import cgi

register=template.Library()

@register.filter(name='ucwords')
def ucwords(string):
	return capwords(string)

@register.filter(name='format_phone')
def format_phone(phone):
	formatted="+1 (" + phone[0:3] + ") " + phone[3:6] + "-" + phone[6:10]
	return formatted



@register.tag
def vardump(parser, token):
    tagname, varname = token.contents.split()
    return VardumpRenderer(varname)

class VardumpRenderer(template.Node):
	def __init__(self, var):
	    self.var = var
	def render(self, context):
	    var = self.var
	    try:
	        var = template.resolve_variable(self.var, context)
	        t = type(var)
	        return cgi.escape( "%s => %s" % (t, var) )
	    except template.VariableDoesNotExist:
	        return 'VariableDoesNotExist'